package com.ebelter.myehc.ui.fragments.bracelet;

import android.graphics.Color;
import android.os.Bundle;

import android.util.TypedValue;
import android.widget.TextView;
import com.ebelter.btcomlib.bases.fragment.BaseFragment;
import com.ebelter.btcomlib.models.bluetooth.products.bracelet.bean.RateBean;
import com.ebelter.btcomlib.utils.AppUtils;
import com.ebelter.btcomlib.utils.TimeUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.views.XLOneDayChartView;
import com.ebelter.myehc.R;
import com.ebelter.myehc.beans.BraTodayData;

import java.util.List;

/**
 * 手环 心率
 */

public class BRA_XL_Fragment extends BaseFragment {
    public static final String TAG = "BRA_Fragment";
    @Override
    protected int setLayoutResouceId() {
        return R.layout.fragment_bra_xl;
    }


    private TextView xl_rate_tv;
    private TextView xl_max_tv;
    private TextView xl_avg_tv;
    private TextView xl_min_tv;


    private TextView xl_max_tv_2;
    private TextView xl_avg_tv_2;
    private TextView xl_min_tv_2;
    private TextView xl_todayTime_tv;

    private XLOneDayChartView xLOneDayChartView;


    @Override
    protected void initView() {
        super.initView();

        FV();
    }

    private void FV() {

        xl_rate_tv=mRootView.findViewById(R.id.xl_rate_tv);
        xl_max_tv=mRootView.findViewById(R.id.xl_max_tv);
        xl_avg_tv=mRootView.findViewById(R.id.xl_avg_tv);
        xl_min_tv=mRootView.findViewById(R.id.xl_min_tv);
        xl_max_tv_2=mRootView.findViewById(R.id.max_xl_tv);
        xl_avg_tv_2=mRootView.findViewById(R.id.avg_xl_tv);
        xl_min_tv_2=mRootView.findViewById(R.id.min_xl_tv);
        xl_todayTime_tv=mRootView.findViewById(R.id.toadytime_tv);
        xLOneDayChartView=mRootView.findViewById(R.id.xLOneDayChartView);


        String local = AppUtils.getLocalStr();
        if (AppUtils.en.equals(local)){
            //英文
            xl_max_tv_2.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);
            xl_avg_tv_2.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);
            xl_min_tv_2.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);
        }else {
            xl_max_tv_2.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
            xl_avg_tv_2.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
            xl_min_tv_2.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
        }

    }

    @Override
    protected void initData(Bundle arguments) {
        super.initData(arguments);
        String timeStr=TimeUtils.formatTime1(System.currentTimeMillis());
        ViewUtils.setTextViewStr(xl_todayTime_tv, TimeUtils.timeFatmat(timeStr,1));

        xLOneDayChartView.setColor1(Color.parseColor("#fdce02"));//警告线的颜色
        xLOneDayChartView.setColor2(getResources().getColor(R.color.redTheme));//曲线的颜色
        xLOneDayChartView.setYValue(40,130);
        xLOneDayChartView.setWarringValue(100);

    }

    public void disRate(RateBean rateBean) {
        ViewUtils.setTextViewStr(xl_rate_tv,rateBean.rate+"");
    }



    public void rateTodayHistory(List<RateBean> list) {
        if (xLOneDayChartView!=null)xLOneDayChartView.setRateOneDayInfos(list);
    }

    //设置实时心率
    public void setRealTimeXLData(RateBean rateBean) {
        ViewUtils.setTextViewStr(xl_rate_tv,rateBean.station==1?rateBean.rate+"":"0");
    }

    public void SetBraTodayData(BraTodayData braTodayData) {
        if (xLOneDayChartView!=null&&braTodayData.list2.size()>0){
            xLOneDayChartView.setYValue(braTodayData.minHeart-5,braTodayData.maxHeart+5);
        }
        rateTodayHistory(braTodayData.list2);
        ViewUtils.setTextViewStr(xl_max_tv,braTodayData.maxHeart+"");
        ViewUtils.setTextViewStr(xl_min_tv,braTodayData.minHeart+"");
        ViewUtils.setTextViewStr(xl_avg_tv,braTodayData.avgHeart+"");
    }
}
